﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PresentationProject;

namespace PresatationProject
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    /// 
    
    public partial class MainWindow : Window
    {
        //private KinectController _kinect;   //声明KinectController对象
        private List<Page> myListPage;      //框架中页的集合
        private int currentPage;                    //当前展示页位置

        public MainWindow()
        {
            InitializeComponent();

            // 设置全屏
            this.WindowState = System.Windows.WindowState.Normal;
            this.WindowStyle = System.Windows.WindowStyle.None;
            this.ResizeMode = System.Windows.ResizeMode.NoResize;
            //this.Topmost = true;

            this.Left = 0.0;
            this.Top = 0.0;
            this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
            this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;


            //_kinect = new KinectController(false);
            myListPage = new List<Page>();
            currentPage = 0;            //初始化显示当前页面计数
            insertPages();              //插入页面的集合
            showPage();
        }


        //处理键盘事件
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
                this.WindowState = System.Windows.WindowState.Maximized;
                this.ResizeMode = System.Windows.ResizeMode.CanResize;
            }
            else if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && e.Key == Key.Enter)
            {
                this.WindowState = System.Windows.WindowState.Normal;
                this.WindowStyle = System.Windows.WindowStyle.None;
                this.ResizeMode = System.Windows.ResizeMode.NoResize;
                //this.Topmost = true;

                this.Left = 0.0;
                this.Top = 0.0;
                this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
                this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
            } 
            else if (e.Key == Key.Space){
                //GGbegin
                //testpage.GG();
                //GGend
            }
            else if (e.Key == Key.Down)
            {
                total.ClassControl.nextClass();
            }
        }

        private void insert(Page myPage)//插入页面
        {
            myListPage.Add(myPage);
        }

        //GGbegin
        TestPage testpage;
        //GGend

        //ClassPage classpage;
        TotalPage total;

        private void insertPages()
        {
            //classpage = new ClassPage();
            //myListPage.Add(classpage);

            total = new TotalPage();
            myListPage.Add(total);

            //GGBegin
            //testpage = new TestPage();
            //myListPage.Add(testpage);
            //GGend

            //创建新的页以及插入界面中
            //ImagePage myImagePage = new ImagePage();
            //TextPage  myTestPage = new TextPage();
            //TextPage myTestPage1 = new TextPage();
            //MouseDrag myMouseDrag = new MouseDrag();
            
            //FirstPage firstPage = new FirstPage();
            //LastPage lastPage = new LastPage();

            //ClassPage1 classPage1 = new ClassPage1();
            //ClassPage2 classPage2 = new ClassPage2();

            //myListPage.Add(firstPage);
            //myListPage.Add(classPage1);
            //myListPage.Add(classPage2);
            //myListPage.Add(lastPage);
            
        }

        public void showPage()//显示页面
        {
            if (currentPage < myListPage.Count && currentPage >= 0)
                this.Content = myListPage[currentPage];
        }

        //public void nextPage()//显示下一页
        //{
        //    if (myListPage.Count > 0)
        //    {
        //        if (currentPage == myListPage.Count - 1)
        //        {
        //            MessageBox.Show("这已经是最后一页了。");
        //        }
        //        else
        //        {
        //            currentPage = (currentPage + 1) % myListPage.Count;
        //            showPage();
        //        }
        //    }

        //}

        //public void priviousPage()//返回前一页
        //{
        //    if (myListPage.Count > 0)
        //    {
        //        if (currentPage == 0)
        //        {
        //            MessageBox.Show("这已经是第一页了。");
        //        }
        //        else
        //        {
        //            currentPage = (currentPage + myListPage.Count - 1) % myListPage.Count;
        //            showPage();
        //        }
        //    }
        //}

        public void showCountPage(int count)//显示指定位置的页面
        {
            //MessageBox.Show("The Number:"+count);
            // MessageBox.Show("The Number:" + myListPage.Count);
            if (count > myListPage.Count || count <= 0)
            {

                MessageBox.Show("The Number Out Of the Size");

            }
            else
            {
                this.Content = myListPage[count - 1];
            }
        }


        /*
        private void Window_MouseDown(object sender, MouseButtonEventArgs e)//鼠标点击事件
        {
            nextPage();
        }
         * */

       

        private void Window_Loaded(object sender, RoutedEventArgs e)//页面加载初始化函数,主要用于kinect的初始化，当项目未使用kinect时，可去除加载函数
        {

           //_kinect.outGR += new KinectController.outGestureRecognizedEventHandler(GestureRecoganized);
        }

        //public void GestureRecoganized(object sender, outGestureRecognizedEventArgs e)//处理函数
        //{
        //    if (e.GID == "RightHandSwipeLeft")
        //        nextPage();
        //    else if (e.GID == "LeftHandSwipeRight")
        //        priviousPage();
        //}

        private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            //nextPage();
        }
    }
}
